package com.saturn.highcharts;

import java.util.List;

import org.json.JSONObject;

public class Line {

	private String name = "";
	private String[] data = null;
	
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String[] getData() {
		return data;
	}
	public void setData(String[] data) {
		this.data = data;
	}
	
	public static String getLineJSON(List<Line> cts) {

		StringBuffer buffer = new StringBuffer();
		String dataitem = "";
		buffer.append("{");

		buffer.append("\"rows\":");
		buffer.append("[");
		
		for (int i = 0; i < cts.size(); i++) {
			buffer.append("{");
			buffer.append("\"name\":" + "\"" + cts.get(i).getName() + "\"");
			buffer.append(",");
			dataitem = "" + cts.get(i).getData()[0] + "";
			for (int j = 1; j < cts.get(i).getData().length-1; j++) {
				dataitem = dataitem + "," + cts.get(i).getData()[j] + "";
			}
			dataitem = dataitem + "," + cts.get(i).getData()[cts.get(i).getData().length-1] +"";
			buffer.append("\"data\":[" + dataitem + "]");
			
			if (i == (cts.size()-1)) {
				buffer.append("}");
			} else {
				buffer.append("},");
			}
			
		}
		buffer.append("]");
		buffer.append("}");
		System.out.println(buffer.toString());
		return buffer.toString();
	}
	
	@Override
	public String toString() {
		return new JSONObject(this).toString();
	}
}
